<template>
	<view>
		<uni-nav-bar :statusBar="true" dark title="权限管理" fixed left-icon="left" @clickLeft="clickLeft">
			<block slot="right">
				<view class="city">
					<view @click="onCreated">
						<uni-icons color="#fff" fontFamily="CustomFont" type="plusempty" :size="20"></uni-icons>
					</view>
				</view>
			</block>
		</uni-nav-bar>
		<view>
			<!-- <view class="tips">
				超级管理员可以管理所有内容联赛管理员可以管理联赛除提现以外的所有内容记录台、裁判可以新建赛程、记录比赛数据(不能删除赛程、添加球员)
			</view> -->
			<view class="addlist">
				<!-- <view class="item" @click="onAdd">
					<view class="icon" style="background: #72bb72;">
						<uni-icons type="weixin" color="#fff" :size="26"></uni-icons>
					</view>
					<text>微信分享添加</text>
				</view> -->
				<view class="item" @click="onAdd">
					<view class="icon">
						<uni-icons type="phone-filled" color="#fff" :size="26"></uni-icons>
					</view>
					<text>录入手机号添加</text>
				</view>
			</view>
			<view class="list" v-for="(item,index) in userList" :key="index" @click="goBackadd(item)">
				<view class="list-left">
					<view class="name">{{item.createUserName}}</view>
					<view class="phone">{{item.phone}}</view>
				</view>
				<view class="list-right">
					<view>{{type[item.type]}}</view>
				</view>
			</view>
		</view>
		<!--  -->
		<uni-popup ref="popup" background-color="#fff" @change="change">
			<view class="popupContent">
				<view>工作人员录制</view>
				<uni-forms class="form" ref="baseForm" :modelValue="baseFormData" :rules="customRules">
					<uni-forms-item class="logo" labelWidth="180rpx" label="角色" required name="teamLogo">
						<uni-data-select collection="opendb-app-list" field="appid as value, name as text" label="应用选择"
							v-model="baseFormData.type" :localdata="range" :clear="false" />
					</uni-forms-item>
					<uni-forms-item labelWidth="180rpx" label="手机号" required name="teamName">
						<uni-easyinput v-model="baseFormData.phone" placeholder="请输入手机号" />
					</uni-forms-item>
				</uni-forms>
				<button @click="oAddUser">
					确定
				</button>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		addPersonnel,
		addPersonnelList
	} from '@/api/personnel/index.js'
	export default {
		data() {
			return {
				baseFormData: {
					type: '',
					level: 1,
					phone: ''
				},
				customRules: {},
				range: [{
						value: 1,
						text: '主裁'
					},
					{
						value: 2,
						text: '副裁'
					},
					{
						value: 3,
						text: '计录台'
					},
					{
						value: 4,
						text: '技术代表'
					},
					{
						value: 5,
						text: '赛季管理员'
					}
				],
				userList: [],
				type: {
					1: "主裁",
					2: "副裁",
					3: "计录台",
					4: "技术代表",
					5: "赛季管理员",
				},
				id: ''
			}
		},
		onLoad({
			id
		}) {
			this.id = id
			this._addPersonnelList(id)
		},
		methods: {
			goBackadd(item) {
				console.log(item)
				uni.setStorageSync('workPeople', item);
				uni.navigateBack()
			},
			clickLeft() {
				uni.navigateBack()
			},
			onAdd() {
				this.$refs.popup.open('center');
			},
			oAddUser() {
				this.$refs['baseForm'].validate().then(res => {
					let contestId = uni.getStorageSync('contestId');
					let organizationId = uni.getStorageSync('scoringWay')
					let userId = uni.getStorageSync('userId')
					let seasonId = uni.getStorageSync('seasonId')
					addPersonnel({
						...this.baseFormData,
						contestId,
						organizationId,
						tournamentId: this.id,
						userId,
						seasonId: seasonId
					}).then(() => {
						console.log(11111)
						this.$refs.popup.close();
						uni.navigateBack()
					})
				})

			},
			_addPersonnelList() {
				this.userList = uni.getStorageSync('otherList')
			}
		}
	}
</script>

<style scoped lang="scss">
	.tips {
		padding: 30rpx;
		background-color: #425E73;
		color: #fff;
	}

	.addlist {
		width: 100%;
		margin-top: 60rpx;
		display: flex;
		justify-content: space-around;

		.item {
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;

			.icon {
				margin-bottom: 20rpx;
				display: flex;
				align-items: center;
				justify-content: center;
				background: #64AEE9;
				width: 100rpx;
				height: 100rpx;
				border-radius: 100%;
			}
		}
	}

	.list {
		width: 100%;
		padding: 32rpx;
		box-sizing: border-box;
		display: flex;
		justify-content: space-between;

		.list-left {
			.name {
				font-size: 32rpx;
			}

			.phone {
				font-size: 28rpx;
				color: #9e9e9e;
			}
		}

		.list-right {
			height: 50rpx;
			padding: 0px 10rpx;
			line-height: 50rpx;
			border: 2rpx solid #eee;
			color: #9e9e9e;
			border-radius: 10rpx;

		}
	}

	.popupContent {
		padding: 30rpx;
	}
</style>